import React, {Component,} from 'react';
import {
    StyleSheet,
    View,
    Animated,
    Image,
    Dimensions,
} from 'react-native';
import PropTypes from 'prop-types';
var WINDOW_WIDTH = Dimensions.get('window').width;
type Props = {
    //图片资源
    source: Image.source,
    //动画执行完毕回调
    animateEnd: PropTypes.func,
};
export default class SplashView extends Component<Props> {

    constructor(props) {
        super(props);
        this.state = {
            // fadeAnim: new Animated.Value(0.5),
            fadeAnim: new Animated.Value(1),
        };
    }

    componentDidMount() {
        const {animateEnd} = this.props;
        Animated.timing(
            this.state.fadeAnim,
            {
                toValue: 1,
                duration: 2000,
            }
        ).start(() => {
            //动画执行完毕
            if (animateEnd) {
                animateEnd()
            }
        });
    }

    render() {
        const {source} = this.props;
        return (
            <View style={{flex:1}}>
                <Animated.Image style={{flex:1,width:WINDOW_WIDTH,height:1,opacity: this.state.fadeAnim}}
                                source={source}/>
            </View>
        );
    }
}